<?php
require_once(OC::$SERVERROOT . "/apps/reports/lib/helper.php");
require_once(OC::$SERVERROOT . "/apps/reports/lib/reports.php");

if (!PFactory::isMasterUser()) {
   echo '您无权访问该资源';
   exit();
}

$model = new PReportsModelReports();
$summary = $model->getSumContrast();

if ($summary === false) {
   jexit('<div class="yahei large noreportsdata">' . ($model->getError() ? $model->getError() : '系统错误') . '</div>');
}

$xtypes = array('resume', 'event', 'offer', 'entry');
$chartTtitles = array(
   'job'    => '新增职位',
   'resume' => '新增简历',
   'event'  => '进入面试',
   'offer'  => '发offer',
   'entry'  => '入职'
);
?>
<? 
if (!empty($summary['lines']['data'])):
   foreach ($summary['lines']['data'] as $x => $data):
?>
<div class="rep_resumefrom" <?=$x=="job" ? "style='margin-top:20px;'" : "" ?>  id="anchor_ctrst_<?=$x?>">
<div class="putcanvas">
   <h5><b><?=$chartTtitles[$x]?></b></b></h5>
   <div id="<?=$x?>Line" data-xtype="<?=$x?>" class="dateLine" style="height:205px; width:100%;"></div>
   <div class="rep_detailtable" style="margin-top:10px;">
      <table width="100%" border="0" cellpadding="0" cellspacing="0">
         <tr>
            <th width="%">时间段</th>
            <? foreach ($summary['lines']['ticks'] as $t): ?>
               <th width="%"><?=$t?></th>
            <? endforeach; ?>
            <th width="%">总计</th>
         </tr>
         <? foreach ($summary['lines']['cnstime'] as $i => $time): ?>
            <tr>
               <td class="tleft"><span><i class="bgc_<?=($i+1)?>"></i> <?=$time?></span></td>
               <? 
                  foreach ($summary['lines']['ticks'] as $j => $t):
                  $c = empty($data[$i][$j]) ? 0 : $data[$i][$j];
               ?>
                  <td><?=$c?></td>
               <? endforeach; ?>
               <td><?=$summary['lines']['total'][$x][$i]?></td>
            </tr>
         <? endforeach; ?>
      </table>
   </div>
</div>
</div>
<?
   endforeach;
endif; 
?>

<? 
if (!empty($summary['bars']['data'])): 
   foreach ($summary['bars']['data'] as $x => $data):
?>
   <div class="rep_resumefrom" <?= $x=='job' ? 'style="margin-top:20px;"' : '' ?> id="anchor_ctrst_<?=$x?>">
      <h5><b><?=$chartTtitles[$x]?></b></h5>

      <div class="clearfix">
         <div id="<?=$x?>Bar" data-xtype="<?=$x?>" class="totalBar pull-left" style="height:205px; width:60%"></div>

         <div class="rep_detailtable pull-right" style="width:35%; margin-top:10px;">
            <table width="100%" border="0" cellpadding="0" cellspacing="0">
               <tr>
                  <th width="35%">时间段</th>
                  <th width="65%"><?=$chartTtitles[$x]?>数</th>
               </tr>
               <? foreach ($summary['bars']['ticks'] as $i => $t): ?>
                  <tr>
                     <td class="medium"><?=$t?></td>
                     <td><?=$data[$i]?></td>
                  </tr>
               <? endforeach; ?>
            </table>
         </div>
      </div>
   </div>
<? 
   endforeach;
endif; 
?>

<script type="text/javascript">
$(document).ready(function(){
   var summary = <?=json_encode($summary)?>;
   var charts = new Array();
   $(window).unbind('resize');

   $('.totalBar').each(function(){
      var xtype = $(this).data('xtype');
      charts[charts.length++] = $.jqplot($(this).attr('id'), [summary.bars.data[xtype]], {
         // The "seriesDefaults" option is an options object that will
         // be applied to all series in the chart.
         seriesDefaults:{
            renderer:$.jqplot.BarRenderer,
            rendererOptions: {
               fillToZero: true,
               barWidth: 45,
               barMargin: 70
            },
            pointLabels: {show: true},
            shadow:false
         },
         // Custom labels for the series are specified with the "label"
         // option on the series option.  Here a series option object
         // is specified for each series.
         series:[
            {showLabel:false,color:'#71c5f4'}
         ],
         // Show the legend and put it outside the grid, but inside the
         // plot container, shrinking the grid to accomodate the legend.
         // A value of "outside" would not shrink the grid and allow
         // the legend to overflow the container.
         legend: {
            show: true,
            placement: 'outsideGrid'
         },
         axes: {
            // Use a category axis on the x axis and use our custom ticks.
            xaxis: {
                renderer: $.jqplot.CategoryAxisRenderer,
                ticks: summary.bars.ticks
            },
            // Pad the y axis just a little so bars can get close to, but
            // not touch, the grid boundaries.  1.2 is the default padding.
            yaxis: {
               min:0,
               pad: 1.00,
               max: summary.bars.max[xtype],
               tickInterval : summary.bars.tickInterval[xtype],
               tickOptions: {formatString: '%d'}
            }
         },
         grid: {
            shadow: false,               // draw a shadow for grid.
            drawGridLines: false,        // wether to draw lines across the grid or not.
            gridLineColor: '#e9e9e9',   // *Color of the grid lines.
            background: '#ffffff',      // CSS color spec for background color of grid.
            borderColor: '#333333',     // CSS color spec for border around grid.
            borderWidth: 0.5,              // draw a shadow for grid.
         }
      });
   });

   $('.dateLine').each(function(){
      var xtype = $(this).data('xtype');
      charts[charts.length++] = $.jqplot($(this).attr('id'),  summary.lines.data[xtype], {
         axes: {
            // Use a category axis on the x axis and use our custom ticks.
            xaxis: {
                renderer: $.jqplot.CategoryAxisRenderer,
                ticks: summary.lines.ticks
            },
            // Pad the y axis just a little so bars can get close to, but
            // not touch, the grid boundaries.  1.2 is the default padding.
            yaxis: {
               min:0,
               pad: 1.00,
               max: summary.lines.max[xtype],
               tickInterval : summary.lines.tickInterval[xtype],
               tickOptions: {formatString: '%d'}
            }
         },
         seriesDefaults: {
            shadow:false,
            lineWidth:1.5,
            markerOptions:{
               shadow:false
            }
         },
         series:[{color:'#06aaff'},{color:'#5fcb17'}],
         highlighter: {
            show: true,
            sizeAdjust: 7.5,
            tooltipAxes: 'y',
            tooltipSeparator: ' , '
            //formatString  : '%s月'
         },
         cursor: {
            show: false
         },
         grid: {
            shadow: false,               // draw a shadow for grid.
            drawGridLines: false,        // wether to draw lines across the grid or not.
            gridLineColor: '#e9e9e9',   // *Color of the grid lines.
            background: '#ffffff',      // CSS color spec for background color of grid.
            borderColor: '#333333',     // CSS color spec for border around grid.
            borderWidth: 0.5            // Opacity of the shadow
         }
      });
   });
   
   $(window).resize(function(){
      $.each(charts, function(i, c){
         c.replot( { resetAxes: { xaxis: true } } );
      });
   });
});
</script>